/*
	Copyright (C) 2009 Salil Bhagurkar
	
	This file is part of ViSE
	
	ViSE is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	ViSE is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public License
	along with ViSE.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <shared.h>


static struct node_fs *graphics_dev = NULL;

int graphics_write(struct node_fs *this, void *buf, u32 offset, u32 count)
{
	struct node_fs *fs;
	int err;
	if(!buf) { //set mode request
		fs_iterator_parse(&fs, "/class/graphics");
		fs_iterator_get_child(&fs);
		while(fs) {
			err = fs->write(fs, buf, offset, count);
			if(!err) {
				graphics_dev = fs;
				return 0;
			}
			fs_iterator_get_next(&fs);
		}
	} else {
		if(!graphics_dev) {
			printk("graphics device not set\n");
			return ESTATEINV;
		} else {
			return graphics_dev->write(graphics_dev, buf, offset, count);
		}
	}
	return ENODEV;
}


static struct node_fs graphics_class = {
	.type = TYPE_FS_CLIENT,
	.name = "graphics",
	NODE_FS_INIT_VARS,
	NODE_FS_INIT_INIT,
	.read = dummy,
	.write = graphics_write,
	.enumerate = dummy,
	.notify = dummy,
	NODE_FS_LIST_INIT,
};



void register_graphics()
{
	fs_link("/class", &graphics_class);
}
